home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 83win / data1.cab / DLL_Toolkit / Source / HTBRadioButton / RadiobuttonDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  6.8 KB  |  274 lines

  1. // RadiobuttonDlg.cpp : implementation file
  2. //    High Tech BASIC, Copyright (C) TransEra Corp 1999, All Rights Reserved.
  3. //
  4. // Author:       Sven Henze, Tech Soft GmbH (Germany)
  5. // Created:      22-Aug-1999
  6. // Last update:  28-Sep-1999
  7. //
  8.  
  9. #include "stdafx.h"
  10. #include "Radiobutton.h"
  11. #include "RadiobuttonDlg.h"
  12. #include "export.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. #define BUTTONHEIGHT 21
  21. #define WIDTHADJUST 25
  22. #define STARTHEIGHT 370
  23. #define HEIGHTADJUST 30
  24.  
  25.  
  26. extern short g_BtnCount;                            // the number of radiobuttons desired
  27. extern long g_Width;                                    // width of the dialog box
  28. extern OPTION g_Option;                                // 1 for modal, 2 for threaded variable update, 3 for threaded with signals
  29. extern CString g_Title;                                // Window title
  30. extern CString    g_Description;                        // Text above radiobuttons will wrap to two lines if too long
  31. extern CString    g_Text[10];                            // radiobutton text
  32. extern int    m_Radio[10];                            // radiobutton state
  33. extern short * g_pPress;
  34. char tmp[256];
  35. extern short save_pressed;            
  36. extern CString g_grouptext;
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // RadioButtonDlg dialog
  40.  
  41.  
  42. RadioButtonDlg::RadioButtonDlg(CWnd* pParent /*=NULL*/)
  43.     : CDialog(RadioButtonDlg::IDD, pParent)
  44. {
  45.     //{{AFX_DATA_INIT(RadioButtonDlg)
  46.         // NOTE: the ClassWizard will add member initialization here
  47.     //}}AFX_DATA_INIT
  48.  
  49.     
  50.     int i;
  51.     
  52.     for ( i=0; i < g_BtnCount; i++) 
  53.         m_Radio[i] = 1;                // resets radio buttons
  54.  
  55.  
  56.     if ( (save_pressed <= 1) || (save_pressed > g_BtnCount) )  
  57.     {
  58.         m_Radio[0] = 0;
  59.         * g_pPress = 1;
  60.     }
  61.  
  62.     for ( i=1; i < g_BtnCount; i++ )
  63.         if ( save_pressed == i+1 )  m_Radio[i] = 0;  // sets appropriate radiobutton
  64.  
  65. }
  66.  
  67. void RadioButtonDlg::DoDataExchange(CDataExchange* pDX)
  68. {
  69.     CDialog::DoDataExchange(pDX);
  70.     //{{AFX_DATA_MAP(RadioButtonDlg)
  71.     DDX_Control(pDX, IDC_RADIO1, m_btn[0]);
  72.     DDX_Control(pDX, IDC_RADIO2, m_btn[1]);
  73.     DDX_Control(pDX, IDC_RADIO3, m_btn[2]);
  74.     DDX_Control(pDX, IDC_RADIO4, m_btn[3]);
  75.     DDX_Control(pDX, IDC_RADIO5, m_btn[4]);
  76.     DDX_Control(pDX, IDC_RADIO6, m_btn[5]);
  77.     DDX_Control(pDX, IDC_RADIO7, m_btn[6]);
  78.     DDX_Control(pDX, IDC_RADIO8, m_btn[7]);
  79.     DDX_Control(pDX, IDC_RADIO9, m_btn[8]);
  80.     DDX_Control(pDX, IDC_RADIO10, m_btn[9]);
  81.     DDX_Radio(pDX, IDC_RADIO1, m_Radio[0]);
  82.     DDX_Radio(pDX, IDC_RADIO2, m_Radio[1]);
  83.     DDX_Radio(pDX, IDC_RADIO3, m_Radio[2]);
  84.     DDX_Radio(pDX, IDC_RADIO4, m_Radio[3]);
  85.     DDX_Radio(pDX, IDC_RADIO5, m_Radio[4]);
  86.     DDX_Radio(pDX, IDC_RADIO6, m_Radio[5]);
  87.     DDX_Radio(pDX, IDC_RADIO7, m_Radio[6]);
  88.     DDX_Radio(pDX, IDC_RADIO8, m_Radio[7]);
  89.     DDX_Radio(pDX, IDC_RADIO9, m_Radio[8]);
  90.     DDX_Radio(pDX, IDC_RADIO10, m_Radio[9]);
  91.     //}}AFX_DATA_MAP
  92. }
  93.  
  94.  
  95. BEGIN_MESSAGE_MAP(RadioButtonDlg, CDialog)
  96.     //{{AFX_MSG_MAP(RadioButtonDlg)
  97.     ON_BN_CLICKED(IDC_BUTTON13, OKPressed)
  98.     ON_BN_CLICKED(IDC_BUTTON14, CancelPressed)
  99.     ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  100.     ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  101.     ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
  102.     ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
  103.     ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
  104.     ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
  105.     ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
  106.     ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
  107.     ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
  108.     ON_BN_CLICKED(IDC_RADIO10, OnRadio10)
  109.     ON_WM_CLOSE()
  110.     //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // RadioButtonDlg message handlers
  115.  
  116. BOOL RadioButtonDlg::OnInitDialog() 
  117. {
  118.     CDialog::OnInitDialog();
  119.     
  120.     SetWindowText(g_Title);                                    // set window title
  121.  
  122.     SetDlgItemText(IDC_TEXT0,g_Description);                // set static text control text
  123.     SetDlgItemText(IDC_TEXT1,g_grouptext);                    // group text
  124.  
  125.     CWnd* pStaticText = GetDlgItem(IDC_TEXT0);                    // get pointer to static text control text
  126.     pStaticText->SetWindowPos(NULL,0,0,g_Width,BUTTONHEIGHT,SWP_NOZORDER | SWP_NOMOVE);    // set width of static text control
  127.     
  128.     CWnd* pStaticGText = GetDlgItem(IDC_TEXT1);                    // get pointer to static text control text
  129.     pStaticGText->SetWindowPos(NULL,0,0,g_Width,24+BUTTONHEIGHT*g_BtnCount,SWP_NOZORDER | SWP_NOMOVE);    // set width of static text control
  130.  
  131.     CWnd* pOKButton = GetDlgItem(IDC_BUTTON13);                    // get pointer to OK button
  132.  
  133.     CWnd* pCancelButton = GetDlgItem(IDC_BUTTON14);                    // get pointer to OK button
  134.  
  135.     // center the 'OK' and 'Cancel buttons
  136.     pOKButton->SetWindowPos(NULL,(g_Width+WIDTHADJUST)/2-72,74+(BUTTONHEIGHT*g_BtnCount),60,23,SWP_NOZORDER);    // set position of OK button
  137.     pCancelButton->SetWindowPos(NULL,(g_Width+WIDTHADJUST)/2+3,74+(BUTTONHEIGHT*g_BtnCount),60,23,SWP_NOZORDER);    // set position of Cancel button
  138.  
  139.  
  140.     long i;
  141.  
  142.     // Setup any used radiobuttons
  143.     for (i = 0; i < g_BtnCount; i++)
  144.     {
  145.         m_btn[i].SetWindowText(g_Text[i]);                        // set radiobutton text
  146.         m_btn[i].SetWindowPos(NULL,0,0,g_Width-18,BUTTONHEIGHT,SWP_NOZORDER | SWP_NOMOVE);    // set radiobutton width
  147.     }
  148.  
  149.     // Destroy the remaining radiobuttons if any...
  150.     for (i = g_BtnCount; i < MAXBUTTON; i++)
  151.     {
  152.         m_btn[i].DestroyWindow();
  153.     }
  154.  
  155.  
  156.     // set window size
  157.     SetWindowPos(NULL,0,0,g_Width+WIDTHADJUST,135+(BUTTONHEIGHT*g_BtnCount),SWP_NOZORDER );
  158.     
  159.     SetForegroundWindow();
  160.  
  161.     return TRUE;  // return TRUE unless you set the focus to a control
  162.                   // EXCEPTION: OCX Property Pages should return FALSE
  163. }
  164.  
  165. void RadioButtonDlg::OnRadio1() 
  166. {    
  167.     * g_pPress = -1;
  168.     UserAct(1);
  169. }
  170.  
  171. void RadioButtonDlg::OnRadio2() 
  172. {    
  173.     * g_pPress = -2;
  174.     UserAct(2);
  175. }
  176.  
  177. void RadioButtonDlg::OnRadio3() 
  178. {    
  179.     * g_pPress = -3;
  180.     UserAct(3);
  181. }
  182.  
  183. void RadioButtonDlg::OnRadio4() 
  184. {    
  185.     * g_pPress = -4;
  186.     UserAct(4);
  187. }
  188.  
  189. void RadioButtonDlg::OnRadio5() 
  190. {    
  191.     * g_pPress = -5;
  192.     UserAct(5);
  193. }
  194.  
  195. void RadioButtonDlg::OnRadio6() 
  196. {    
  197.     * g_pPress = -6;
  198.     UserAct(6);
  199. }
  200.  
  201. void RadioButtonDlg::OnRadio7() 
  202. {    
  203.     * g_pPress = -7;
  204.     UserAct(7);
  205. }
  206.  
  207. void RadioButtonDlg::OnRadio8() 
  208. {    
  209.     * g_pPress = -8;
  210.     UserAct(8);
  211. }
  212.  
  213. void RadioButtonDlg::OnRadio9() 
  214. {    
  215.     * g_pPress = -9;
  216.     UserAct(9);
  217. }
  218.  
  219. void RadioButtonDlg::OnRadio10() 
  220. {    
  221.     * g_pPress = -10;
  222.     UserAct(10);
  223. }
  224.  
  225. void RadioButtonDlg::OnClose() 
  226. {        
  227.     CDialog::OnClose();
  228. }
  229.  
  230.  
  231.  
  232. void RadioButtonDlg::UserAct(short select)
  233. {    * g_pPress = select;                            // set Basic memory to show input value (option    VARIABLE, but it is always done)
  234.  
  235.     switch (g_Option)
  236.     {    case modal:
  237.             EndDialog(0);                    // shut down modal dialog
  238.             break;
  239.  
  240.         case signal:
  241.             Signal(select);                        // set signal for SIGNAL option dialog
  242.             break;
  243.  
  244.           default:
  245.             break;
  246.     }    
  247.  
  248. }
  249.  
  250.  
  251.  
  252.  
  253. void RadioButtonDlg::OKPressed()
  254. {
  255. short i;
  256.  
  257.     if (*g_pPress <0) * g_pPress=(-1)* *g_pPress;
  258.  
  259.     for (i=1; i<=10;i++) if (* g_pPress == i) UserAct(i);
  260.  
  261.     return;
  262.  
  263. }
  264.  
  265.  
  266. void RadioButtonDlg::CancelPressed()
  267. {
  268.  
  269.     // insert some processing here
  270.     * g_pPress = 0;
  271.     EndDialog(0);                    // shut down  dialog
  272.  
  273. }
  274.